<%@ page language="java" contentType="text/html; charset=UTF-8" 
 pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt"  uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ include file="index.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
	<!-- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="favicon.ico" >
    <link rel="Shortcut Icon" href="favicon.ico" /> -->
    <title>主页</title>
    <meta name="keywords" content="耶回收">
    <meta name="description" content="耶回收">
</head>
<style type="text/css">
/* .select{

width:80px;
height:30px;

} */


</style>
<body>
<!--_表格--开始-->
<section class="Hui-article-box">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span>
        评估管理
        <span class="c-gray en">&gt;</span>
        评估商品管理
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <div class="text-c">
				<!-- 按分类，品牌，商品名称搜索  select-box inline-->
				<form action="content-1_1" method="POST">
				<span class="select-box inline">
				<select class="select" name="classify" onchange="getbrandByid()" id="classifyselect" style="width:120px;">
					<option value="">请选择</option>
					<c:forEach items="${classifylist }" var="classify">
					<option value="${classify.cid }" <c:if test="${searchitem.cid==classify.cid}">selected="selected"</c:if>>${classify.classifyname }</option>
					</c:forEach>
				</select>
				</span>
				<span class="select-box inline">
				<select class="select" name="brand" id="brandselect" style="width:120px;">
				     <option value="">请选择</option>
					 <c:forEach items="${brandlist }" var="brand">
					<option value="${brand.pid }" <c:if test="${searchitem.pid==brand.pid}">selected="selected"</c:if>>${brand.brandname }</option>
					</c:forEach>
				</select>
				</span>
              
                <input value="${searchitem.model}" type="text" name="bname" placeholder=" 回收商品名称" style="width:250px" class="input-text"/>
                <button id="searchitem"  class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i>搜索评估商品</button></form>
            </div>
             <!-- 搜索模块结束 -->
            <div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
				 <shiro:hasPermission name="commodity"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a></shiro:hasPermission>
				 <shiro:hasPermission name="commodity"><a class="btn btn-primary radius" href="addBackitem"><i class="Hui-iconfont">&#xe600;</i> 添加评估商品</a></shiro:hasPermission>
				</span>
				<span style="margin-left:30px;color:#c98906;"><i>系统提示:前台网站只显示状态为评估中的回收商品</i></span>
                <span class="r">共有数据：<strong>${pageinfo.total }</strong> 条</span>
            </div>   
                <table class="table table-border table-bordered table-bg table-hover table-sort">
                    <thead>
                    <tr class="text-c">
                        <th width="25"><input type="checkbox" name="" value=""></th>
                        <th width="30">商品序号</th>
                        <th width="75">商品名称</th>
                        <th width="100">创建时间</th>
                        <th width="100">更新时间</th>
                        <th width="40">回收数量</th>
                        <th width="80">商品状态</th>
                       <shiro:hasPermission name="commodity"><th width="120">操作</th></shiro:hasPermission> 
                    </tr>
                    </thead>
                    <tbody id="tb">
                      <c:forEach items="${pageinfo.list}" var="backitem">
                    <c:if test="${pageinfo.total==0}">暂无数据</c:if>
                     <tr class="text-c">
                      <td ><input type="checkbox" value="${backitem.id }" name=""></td>
                        <td  width="30">${backitem.id }</td>
                        <td ><a style="cursor:pointer;color:blue;" class="text-primary" onclick="backitem_get('商品详情','getBackinfo?id=${backitem.id}')" title="查看详细信息">${backitem.model }</a></td>
                       <td  width="60"> <fmt:formatDate value="${backitem.backtime }" pattern="yyyy-MM-dd"/> </td >
                       <td  width="60" class="updatetime"> <fmt:formatDate value="${backitem.updatetime }" pattern="yyyy-MM-dd"/> </td>
                        <td  width="40">${backitem.stocknum }个</td>
               <c:if test="${backitem.backstatus==0}"> <td class="td-status"><span class="label label-defaunt radius">已下架</span></td></c:if>
               <c:if test="${backitem.backstatus==1}"> <td class="td-status"><span class="label label-success radius">评估中</span></td></c:if>
                       <shiro:hasPermission name="commodity"><td class="f-14 td-manage">
               <c:if test="${backitem.backstatus==1}"><a style="text-decoration:none" onClick="article_stop(this,'${backitem.id }')" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a></c:if>
               <c:if test="${backitem.backstatus==0}"><a style="text-decoration:none" onClick="article_start(this,'${backitem.id }')" href="javascript:;" title="评估"><i class="Hui-iconfont">&#xe603;</i></a></c:if>           
                            <a style="text-decoration:none" class="ml-5" href="backitemEdit?id=${backitem.id }" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>
                            <a style="text-decoration:none" class="ml-5" onclick="backitem_del(this,${backitem.id })" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a></td></shiro:hasPermission>
                    </tr>
                    </c:forEach>
                    </tbody>
                </table>
                        <strong>一共${pageinfo.pages}页</strong>
                        <strong>当前页${pageinfo.pageNum}</strong>
                 <span class="layui-breadcrumb">
                 <c:if test="${pageinfo.pageNum>1}"><a href="content-1_1.html?npage=1&bname=${searchitem.model}&classify=${searchitem.cid }&brand=${searchitem.pid}">第一页</a></c:if>
                 <c:if test="${pageinfo.pageNum==1}"><a href="javascript:">第一页</a></c:if>
                 <c:if test="${pageinfo.pageNum==1}"><a href="javascript:">上一页</a></c:if>
                 <c:if test="${pageinfo.pageNum>1}"><a href="content-1_1.html?npage=${pageinfo.prePage}&bname=${searchitem.model}&classify=${searchitem.cid }&brand=${searchitem.pid}">上一页</a></c:if>
                 <c:if test="${pageinfo.pageNum<pageinfo.pages }"><a href="content-1_1.html?npage=${pageinfo.nextPage}&bname=${searchitem.model}&classify=${searchitem.cid }&brand=${searchitem.pid}">下一页</a></c:if>
                 <c:if test="${pageinfo.pageNum==pageinfo.pages }"><a href="javascript:">下一页</a></c:if> 
                 <c:if test="${pageinfo.pageNum==pageinfo.pages}">  <a href="javascript:">最后一页</a></c:if>
                 <c:if test="${pageinfo.pageNum<pageinfo.pages}"><a href="content-1_1.html?npage=${pageinfo.pages}&bname=${searchitem.model}&classify=${searchitem.cid }&brand=${searchitem.pid}">最后一页</a></c:if>
             </span>
         </article>
        </div>
  </section>
<script type="text/javascript">
    $('.table-sort').dataTable({
        "aaSorting": [[ 1, "desc" ]],//默认第几个排序
        "bStateSave": true,//状态保存
        "aoColumnDefs": [
            //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
            {"orderable":false,"aTargets":[0,8]}// 不参与排序的列
        ]
    });

 
    /*二级联动菜单*/
    
     function getbrandByid (){
    	var cid =$("#classifyselect").val();
    	
    	$.ajax({
            type: 'POST',
            url: 'getbrandByid',
            data:{"cid":cid},
            dataType: 'json',
            success: function(data){
            	
            	$("#brandselect").empty();
            	$("#brandselect").append('<option value="">请选择</option>');
            	for(var i=0;i<data.brands.length;i++){
            	$("#brandselect").append("<option value="+data.brands[i].pid+">"+data.brands[i].brandname+"</option>");
            	}              	
            },
            error:function(data) {
                console.log(data.msg);
            },
        });
    	
    }
  
    
    
    
    
    /* 编辑商品 */
    function backitem_edit(title,url,id,w,h){
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
       
        
    }
    
    
    layer.open({
		type: 2,
		area: [w+'px', h +'px'],
		fix: false, //不固定
		maxmin: true,
		shade:0.4,
		title: title,
		content: url
		 
	});  
    
    /*查看商品详情*/
    function backitem_get(title,url){
        var index = layer.open({
            type: 2,
            move:false,
            anim:0,
            fixed:false,
            shadeClose:true,
            title: title,
            area: [630+'px', 580 +'px'],
            shade:0.3,
            content:url
           
        });
        
    }

   /*批量删除*/
   function datadel(){
	  console.log("-----进入批量删除的方法------");
	  var tds = new Array();
       //获取所有的tr标签元素集合
	   tds=document.getElementById("tb").getElementsByTagName("tr");
		  var td_s = new Array();
		 
		  for(var i=0;i<tds.length;i++){
		  var tdc =tds[i].getElementsByTagName("td")[0].getElementsByTagName("input")[0];
		  var tdcheck =$(tdc);
		  console.log(tdcheck.is(":checked"));
		  if(tdcheck.is(":checked")){
		    //如果td被选中 则td的id值放入数组中
			td_s.push(tdcheck.val());
		    
		 } 
		  } 
	   //判断是否有被选中删除的记录 
	   if(td_s.length>0){
		   //发出批量删除ajax 删除请求
		   layer.confirm('确认要删除吗？',{ btn: ["确定","取消"] },function(index){
	           $.ajax({
	               type: 'POST',
	               url: 'deleteBackItems',
	               data:{"td_s":td_s},
	               dataType: 'json',
	               success: function(val){
	               	layer.close(index);
	               layer.msg("删除成功",{icon:1,time:2000});
	               	window.location.href = window.location.href;                	
	               },
	               error:function(data) {
	                   console.log(data.msg);
	               },
	           });
	       });
	   }else{ 
		   
		   layer.msg("请选择要删除的数据！",{time:2000});
		 
	   }
	   
   } 

   /*回收商品-删除*/
   function backitem_del(obj,id){
       layer.confirm('确认要删除吗？',{ btn: ["确定","取消"] },function(index){
           $.ajax({
               type:"POST",
               url:"deleteBackItem",
               data:{"id":id},
               dataType: "json",
               success: function(data){
            	 layer.close(index);
                 $(obj).parents("tr").remove();
                 layer.msg("删除成功！",{icon: 1,time:1000});
               //window.location.href = window.location.href;                	
               },
               error:function(data) {
               },
           });
       });
       
       /*  $(obj).parents("tr").remove();
      	$("#msg").html("删除成功！").show();
        $("#msg").animate({
	           opacity: "hide"
	       }, 4000); */
   }

  //改变商品状态的ajax 方法
  function changeBackStatu(id,url){
	  
	  $.ajax({
          type: "POST",
          url:url,
          data:{id:id},
          dataType:"json",
          success: function(data){
        	  
          },
          error:function(data) {
              console.log("ajax通讯异常");
          }
      });
	  
  }
   
   
   

    
    /*商品下架*/
    function article_stop(obj,id){
        layer.confirm('确认要下架吗？',{ btn: ["确定","取消"] },function(index){
        	$.ajax({
                type: "POST",
                url:"changeBackStatus",
                data:{"id":id},
                dataType:"json",
                success: function(data){
                	 layer.close(index);
                	$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="article_start(this,'+id+')" href="javascript:;" title="发布"><i class="Hui-iconfont">&#xe603;</i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
                    $(obj).remove();
                    layer.msg('已下架!',{icon: 5,time:1000});	
              	  
                },
                error:function(data) {
                    layer.msg("ajax异常！操作失败");
                }
            });  
          
        });
    }

    /*商品上架*/
    function article_start(obj,id){
        layer.confirm('确认要上架吗？',{ btn: ["确定","取消"] },function(index){
        	 $.ajax({
                 type: "POST",
                 url:"changeBackStatus",
                 data:{"id":id},
                 dataType:"json",
                 success: function(data){
                	 layer.close(index);
                	 $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="article_stop(this,'+id+')" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a>');
                     $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">评估中</span>');
                     $(obj).remove();
                     layer.msg('已上架!',{icon: 6,time:1000});
               	  
                 },
                 error:function(data) {
                	 layer.msg("ajax异常！操作失败");
                 }
             });
        	
        	
           
        });
    }
   
    
    
    
    /*商品上线*/
    function article_shenqing(obj,id){
        $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">待审核</span>');
        $(obj).parents("tr").find(".td-manage").html("");
        layer.msg('已提交申请，耐心等待审核!', {icon: 1,time:2000});
    }
</script>
</body>
</html>